home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / ComponentEvent.java < prev    next >
Text File  |  1998-09-22  |  3KB  |  116 lines

  1. /*
  2.  * @(#)ComponentEvent.java    1.15 98/07/01
  3.  *
  4.  * Copyright 1995-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.event;
  16.  
  17. import java.awt.AWTEvent;
  18. import java.awt.Event;
  19. import java.awt.Component;
  20. import java.awt.Rectangle;
  21.  
  22. /**
  23.  * The root event class for all component-level events.
  24.  * These events are provided for notification purposes ONLY;
  25.  * The AWT will automatically handle component moves and resizes
  26.  * internally so that GUI layout works properly regardless of
  27.  * whether a program is receiving these events or not.
  28.  *
  29.  * @see ComponentListener
  30.  *
  31.  * @version 1.15 07/01/98
  32.  * @author Carl Quinn
  33.  */
  34. public class ComponentEvent extends AWTEvent {
  35.  
  36.     /**
  37.      * Marks the first integer id for the range of component event ids.
  38.      */
  39.     public static final int COMPONENT_FIRST        = 100;
  40.  
  41.     /**
  42.      * Marks the last integer id for the range of component event ids.
  43.      */
  44.     public static final int COMPONENT_LAST        = 103;
  45.  
  46.    /**
  47.      * The component moved event type.
  48.      */
  49.     public static final int COMPONENT_MOVED    = COMPONENT_FIRST;
  50.  
  51.     /**
  52.      * The component resized event type.
  53.      */
  54.     public static final int COMPONENT_RESIZED    = 1 + COMPONENT_FIRST;
  55.  
  56.     /**
  57.      * The component shown event type.
  58.      */
  59.     public static final int COMPONENT_SHOWN    = 2 + COMPONENT_FIRST;
  60.  
  61.     /**
  62.      * The component hidden event type.
  63.      */
  64.     public static final int COMPONENT_HIDDEN    = 3 + COMPONENT_FIRST;
  65.  
  66.     /*
  67.      * JDK 1.1 serialVersionUID 
  68.      */
  69.     private static final long serialVersionUID = 8101406823902992965L;
  70.  
  71.     /**
  72.      * Constructs a ComponentEvent object with the specified source component 
  73.      * and type.
  74.      * @param source the component where the event originated
  75.      * @id the event type
  76.      */
  77.     public ComponentEvent(Component source, int id) {
  78.         super(source, id);
  79.     }
  80.  
  81.     /**
  82.      * Returns the component where this event originated.
  83.      */
  84.     public Component getComponent() {
  85. //        return (source instanceof Component) ? (Component)source : null;
  86.         return (Component)source; // cast should always be OK, type was checked in constructor
  87.     }
  88.  
  89.     public String paramString() {
  90.         String typeStr;
  91.         Rectangle b = (source !=null
  92.                ? ((Component)source).getBounds()
  93.                : null);
  94.  
  95.         switch(id) {
  96.           case COMPONENT_SHOWN:
  97.               typeStr = "COMPONENT_SHOWN";
  98.               break;
  99.           case COMPONENT_HIDDEN:
  100.               typeStr = "COMPONENT_HIDDEN";
  101.               break;
  102.           case COMPONENT_MOVED:
  103.               typeStr = "COMPONENT_MOVED ("+ 
  104.                          b.x+","+b.y+" "+b.width+"x"+b.height+")";
  105.               break;
  106.           case COMPONENT_RESIZED:
  107.               typeStr = "COMPONENT_RESIZED ("+ 
  108.                          b.x+","+b.y+" "+b.width+"x"+b.height+")";
  109.               break;
  110.           default:
  111.               typeStr = "unknown type";
  112.         }
  113.         return typeStr;
  114.     }
  115. }
  116.